cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project(recipe-04 LANGUAGES CXX)

set(CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(CXX_EXTENSIONS OFF)

set(USE_LIBRARY OFF)

message(STATUS "Compile sources into a library ? ${USE_LIBRARY}")

set(BUILD_SHARED_LIBS OFF)

list(APPEND _source Message.hpp Message.cpp)

if(USE_LIBRARY)
    #add_library will create a static library
    #since BUILD_SHARED_LIBS is OFF
    add_library(message ${_sources})
    add_executable(hello-world hello-world.cpp)
    target_link_libraries(hello-world message)
else()
    add_executable(hello-world hello-world.cpp ${_source})
endif()

option(FOO_ENABLE "Enable Foo" ON)
if(FOO_ENABLE)
  set(FOO_STRING "foo")
endif()
configure_file(foo.h.in foo.h @ONLY)